package GUI;
/**
 * Statistical report for the principle 
 * Grades between classes for a selected teacher
 */

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import Common.*;


public class StatRepBClasses4Teacher extends JPanel {
	private JLabel lblHistogram = null;
	private JLabel lblSelectTeacher = null;
	private JButton btnShowReport = null;
	private JComboBox selTeacherCb = null;
	
	public Login myLoginFrame = null;
	public UserPrinciple user;
	public PrincipleMainMenu prmn = null;
	private String selTeacher=null;
	private String tid = null;

	private Histogram his = null;
	
	
	
	public JComboBox getSelTeacherComboBox(PrincipleMainMenu prmn)
	{
		
		Vector<String> data = new Vector<String>();
		int i;
	//	System.out.println("Size "+prmn.user.dataHistograms.BclassesForTeacher.size());
		
		for(i=0;i<prmn.user.Teachers.size();i++)
		{
			data.add(prmn.user.Teachers.get(i).FirstName+" "+prmn.user.Teachers.get(i).LastName+" "+prmn.user.Teachers.get(i).tid);
		}
		if(selTeacherCb==null)
		{
			
		selTeacherCb = new JComboBox(data);
		selTeacherCb.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					
					selTeacher = selTeacherCb.getSelectedItem().toString();
					System.out.println(selTeacher);
					//TODO show all the courses that the student isnt registered to and he graduated from the intro courses needed to study this courses

				}
			});
		selTeacherCb.setBounds(167, 80, 208, 22);
		}
		return selTeacherCb;
		
	}
	
	public JButton getShowReportBtn(final PrincipleMainMenu prmn)
	{
		if(btnShowReport==null)
		{
			btnShowReport = new JButton("Show report");
			btnShowReport.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					his=null;
					prmn.user.setSelTeacher(selTeacher);
					String[] temp = selTeacher.split(" ");
					tid = temp[2];
					System.out.println(tid);
					prmn.myLoginFrame.client.handleMessageFromClientUI("DataForHistBetweenClassesToChosenTeacher "+tid);
					while(prmn.user.dataHistograms.BclassesForTeacher==null);
					System.out.println("mIStatTeachersClass");
					his  = prmn.getHistogram(prmn.user.dataHistograms.BclassesForTeacher.size());
					System.out.println("trying to set size");
					System.out.println("size is: "+prmn.user.dataHistograms.BclassesForTeacher.size());
					
					
					//for(int i=0;i<prmn.user.dataHistograms.BclassesForTeacher.size();i++)
					//{
					//	his.setData(prmn.user.dataHistograms.BclassesForTeacher.get(i).AvgGrade);
						
					//}
					//his.setArrSize(prmn.user.dataHistograms.BclassesForTeacher.size());
				//	his.setData(prmn);
					his.showHistogram();
					//prmn.setContentPane(his);
					//TODO show all the courses that the student isnt registered to and he graduated from the intro courses needed to study this courses

				}
			});
			btnShowReport.setBounds(400, 254, 93, 23);
			
		}
		return btnShowReport;
	}
	
	private void initialize(PrincipleMainMenu prmn)
	{
		setLayout(null);
		
		 lblHistogram = new JLabel("Histogram of grades between classes for one teacher ");
		lblHistogram.setBounds(350, 11, 51, 14);
		add(lblHistogram);
		
		 lblSelectTeacher = new JLabel("Select Teacher:");
		lblSelectTeacher.setBounds(49, 84, 75, 14);
		add(lblSelectTeacher);
		
		add(getSelTeacherComboBox(prmn));
		
		add(getShowReportBtn(prmn));
		
	}
	
	
	public StatRepBClasses4Teacher(PrincipleMainMenu prmn) {
		super();
		initialize(prmn);
		
	}
}
